// pages/seeMyAppoint/seeMyAppoint.js
var util2 = require('../../utils/util2');
Page({
  data: {
    appoint: {},
    nowNumber: 0,
    today: util2.formatTime(new Date()),
    nowNumberS: '',
    flowId:'',
    userType:'',
    numberS:''
  },

  onLoad(options) {
    var that = this
    let user=wx.getStorageSync('user')
    console.log(options.flowId)
    that.setData({
      flowId:options.flowId,
      userType:user.userType
    })
    //根据flowId去找这条appoint信息
    wx.cloud.callFunction({
      name: 'appoint',
      data: {
        action: 'findFlowId',
        flowId: options.flowId
      }
    }).then(res => {
      console.log('根据folwId查找appoint{}信息成功', res)
      that.setData({
        appoint: res.result.data[0],
        numberS:String(res.result.data[0].number)
      })
    }).catch(res => {
      console.log('根据folwId查找appoint{}信息失败', res)
    })
    //根据医生id寻找当前排号
    setTimeout(() => {
      wx.cloud.callFunction({
        name: 'doctorInfo',
        data: {
          action: 'findOneId',
          doctorId: that.data.appoint.doctorInfo.doctorId
        }
      }).then(res => {
        console.log('根据doctorId获取当前排号成功', res.result.data[0].nowNumber)
        that.setData({
          nowNumber: res.result.data[0].nowNumber,
          nowNumberS: String(res.result.data[0].nowNumber)
        })
      }).catch(res => {
        console.log('根据doctorId获取当前排号失败', res)
      })
    }, 1000);
  },
  onUnload() {
    // wx.switchTab({
    //   url: '/pages/home/home',
    // })
    // wx.navigateBack({
    //   delta: 1,
    // })
  },
  //取消预约
  del(){
    var that=this
    wx.cloud.callFunction({
      name:'appoint',
      data:{
        action:'changePasedByFlowId',
        flowId:that.data.flowId,
        isPassed:true
      }
    }).then(res=>{
      console.log('取消预约成功',res)
      wx.showToast({
        title: '取消预约成功',
      })
      setTimeout(() => {
        wx.navigateBack({
          delta:1,
        })
      }, 1000);
    }).catch(res=>{
      console.log('取消预约失败',res)
      wx.showToast({
        icon:"none",
        title: '取消预约失败，请检查网络',
      })
    })
  }


})